<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        let findNumber = function(nums,target){
            let left = 0;
            let right = nums.length-1;
            while(left <= right){
                let middle = Math.floor((left + right) / 2);
                if(nums[middle] > target){
                    right = middle-1;
                }else if(nums[middle] < target){
                    left = middle+1;
                }else {
                    return middle;
                }
            }
            return -1;
        }

        let nums = [1,4,6,8,9,23];
        console.log('数字8的下标: ' + findNumber(nums,8));
        console.log('数字10的下标: ' + findNumber(nums,10));

    </script>
</body>
</html>